﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace quanlyktx.hethong
{
    public partial class frmdangnhap : DevComponents.DotNetBar.Office2007Form 
    {
        public frmdangnhap()
        {
            InitializeComponent();
        }
        ketnoi kn = new ketnoi();
        private DataTable dt = new DataTable();
        private SqlDataAdapter da = new SqlDataAdapter();
        private void btndangnhap_Click(object sender, EventArgs e)
        {
            SqlConnection cn = kn.taokn();
            cn.Open();
            SqlCommand cmd = new SqlCommand("dangnhap", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@tendn", SqlDbType.NVarChar).Value = txtuser.Text;
            cmd.Parameters.Add("@matkhau", SqlDbType.NVarChar).Value = txtpass.Text;
            da.SelectCommand = cmd;
            da.Fill(dt);
            if(dt.Rows.Count ==0)
            {
                MessageBox.Show("Đăng nhập ko hợp lệ","lỗi",MessageBoxButtons.OK,MessageBoxIcon.Error);
                txtpass.ResetText();
                txtuser.ResetText();
            }
            else 
            {
                MessageBox.Show("Đăng nhập thành công","thông báo");
                frmmain main=new frmmain();
                main.enableFormMain(dt.Rows[0]["tendn"].ToString());
                main.ShowDialog();
                this.Hide();
            }
        }

        private void btnhuy_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
